package tuiLayer;
import java.util.*;

public class MainUI {
    private CustomerUI customerUI;
    private LoanUI loanUI;
    private SellUI sellUI;
    private ItemUI itemUI;
    private ContractorUI contractorUI;
    private StatisticUI statisticUI;
    
    public MainUI(){
        customerUI=new CustomerUI ();
        loanUI=new   LoanUI();
        sellUI=new SellUI();
        itemUI= new ItemUI();
        contractorUI= new ContractorUI();
        statisticUI= new StatisticUI ();
        start();
    }
    
    private void start() {
        mainMenu();
    }

    private void mainMenu() {
        boolean stop = false;
        while (!stop) {
            int choice = writeMainMenu();
            switch (choice) {
                case 0:
                    stop = true;
                    break;
                case 1:
                    customerUI.start();
                    break;
                case 2:
                    itemUI.start();
                    break;
                case 3:
                    contractorUI.start();
                    break;
                case 4:
                    sellUI.start();
                    break;
                case 5:
                    loanUI.start();
                    break;
                case 6:
                    statisticUI.start();
                    break;
                default: System.out.println("Please enter a valid choice.");
            }
        }
        System.out.println("\nGoodbye!");
    }
    
    private int writeMainMenu() {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\n*****Main Menu*****");
        System.out.println("(0) Exit");
        System.out.println("(1) Customer CRUD");
        System.out.println("(2) Item CRUD and Stock");
        System.out.println("(3) Contractor CRUD");
        System.out.println("(4) Sell Menu");
        System.out.println("(5) Loan Menu");
        System.out.println("(6) Statistic");
        System.out.println("\nRemember: you can always stop an action by pressing 0");
        System.out.println("\nType your choice:");
        
        int choice = keyboard.nextInt();
        return choice;
    }
}